package com.hh.service.Impl;

import com.hh.dto.ResultDTO;
import com.hh.mapper.ApplyMapper;
import com.hh.model.ApplyModel;
import com.hh.service.ApplyService;
import com.hh.until.JSONCopy;
import com.hh.vo.ApplyVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ApplyServiceImpl implements ApplyService {

    @Autowired
    private ApplyMapper applyMapper;

    @Override
    public ResultDTO add(ApplyVO applyVO) {
        ApplyModel applyModel = JSONCopy.copy(applyVO, ApplyModel.class);
        return ResultDTO.getDto(applyMapper.add(applyModel), null);
    }

    @Override
    public ResultDTO delete(ApplyVO applyVO) {
        ApplyModel applyModel = JSONCopy.copy(applyVO, ApplyModel.class);
        return ResultDTO.getDto(applyMapper.delete(applyModel), null);
    }

    @Override
    public ResultDTO update(ApplyVO applyVO) {
        ApplyModel applyModel = JSONCopy.copy(applyVO, ApplyModel.class);
        return ResultDTO.getDto(applyMapper.update(applyModel), null);
    }

    @Override
    public ResultDTO findAll(ApplyVO applyVO) {
        ApplyModel applyModel = JSONCopy.copy(applyVO, ApplyModel.class);
        applyModel.setPage((applyModel.getPage()-1)*applyModel.getLimit());
        List<ApplyModel> applyModelList = applyMapper.findAll(applyModel);
        return ResultDTO.getDto(applyMapper.count(applyModel),applyModelList);
    }

    @Override
    public ResultDTO findById(ApplyVO applyVO) {
        ApplyModel applyModel = JSONCopy.copy(applyVO, ApplyModel.class);
        return ResultDTO.getDto(0,applyMapper.findById(applyModel));
    }

    @Override
    public ResultDTO count(ApplyVO applyVO) {
        ApplyModel applyModel = JSONCopy.copy(applyVO, ApplyModel.class);
        return ResultDTO.getDto(applyMapper.count(applyModel),null);
    }

    public ResultDTO reply(ApplyVO applyVO) {
        ApplyModel applyModel = JSONCopy.copy(applyVO, ApplyModel.class);
        return ResultDTO.getDto(applyMapper.reply(applyModel), null);
    }
}
